import md5 from 'js-md5';
import store from 'src/store';
import { httpUrl } from 'api/config';
import { ajaxPost } from 'api/axios';
import { changeDataType } from 'common/js/util';

export function changePsw(obj) {
	let url = `${httpUrl}/changePassword`;
	
	let data = {
		id: store.getters.User.userId,
		oldPassword: md5(obj.oldPsw),
		newPassword: md5(obj.newPsw)
	};
	
	return ajaxPost(url, changeDataType(data))
		.then(res => {
			return Promise.resolve(res.data)
		})
		.catch(res => {
			return Promise.reject(res)
		})
}

export function getRole() {
	
	let url = `${httpUrl}/listMenu`;
	
	let data = {};
	
	return ajaxPost(url, changeDataType(data))
		.then(res => {
			return Promise.resolve(res)
		})
		.catch(res => {
			return Promise.reject(res)
		})
}